package net.sk.china.city.controller;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import net.sk.china.city.controller.base.BaseController;
import net.sk.china.city.domain.dto.AjaxResult;
import net.sk.china.city.domain.ArProductCategory;
import net.sk.china.city.service.IArProductCategoryService;
import net.sk.china.city.domain.dto.TableDataInfo;

/**
 * 商品分类Controller
 * 
 * @author gxf
 * @date 2024-03-29
 */
@Api(tags = "商品类别")
@RequiredArgsConstructor
@RestController
@RequestMapping("/yigoHome/category")
public class ArProductCategoryController extends BaseController
{
    @Autowired
    private IArProductCategoryService arProductCategoryService;

    /**
     * 查询商品分类列表
     */
    @ApiOperation("类别列表")
    @PreAuthorize("hasAnyAuthority('yigoHome:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArProductCategory arProductCategory)
    {
        startPage();
        List<ArProductCategory> list = arProductCategoryService.selectArProductCategoryList(arProductCategory);
        return getDataTable(list);
    }

    /**
     * 导出商品分类列表
     */
//    @PreAuthorize("@ss.hasPermi('yigoHome:category:export')")
//    @Log(title = "商品分类", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, ArProductCategory arProductCategory)
//    {
//        List<ArProductCategory> list = arProductCategoryService.selectArProductCategoryList(arProductCategory);
//        ExcelUtil<ArProductCategory> util = new ExcelUtil<ArProductCategory>(ArProductCategory.class);
//        util.exportExcel(response, list, "商品分类数据");
//    }

    /**
     * 获取商品分类详细信息
     */
    @ApiOperation("类别详情")
    @PreAuthorize("hasAnyAuthority('yigoHome:category:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(arProductCategoryService.selectArProductCategoryById(id));
    }

    /**
     * 新增商品分类
     */
    @ApiOperation("新增类别")
    @PreAuthorize("hasAnyAuthority('yigoHome:category:add')")
    @PostMapping
    public AjaxResult add(@RequestBody ArProductCategory arProductCategory)
    {
        return toAjax(arProductCategoryService.insertArProductCategory(arProductCategory));
    }

    /**
     * 修改商品分类
     */
    @ApiOperation("修改类别")
    @PreAuthorize("hasAnyAuthority('yigoHome:category:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody ArProductCategory arProductCategory)
    {
        return toAjax(arProductCategoryService.updateArProductCategory(arProductCategory));
    }

    /**
     * 删除商品分类
     */
    @ApiOperation("删除类别")
    @PreAuthorize("hasAnyAuthority('yigoHome:category:remove')")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(arProductCategoryService.deleteArProductCategoryByIds(ids));
    }

    /**
     * 获取所有类别名和id
     */
    @ApiOperation("类别名和id")
    @GetMapping("/getNameAndId")
    public AjaxResult getNameAndId()
    {
        return success(arProductCategoryService.getNameAndId());
    }

    @ApiOperation("修改类别状态")
    @PreAuthorize("hasAnyAuthority('information:articleCategory:edit')")
    @PostMapping("/updateStatus")
    public AjaxResult updateStatus(@RequestBody ArProductCategory arProductCategory)
    {
        return success(arProductCategoryService.updateStatus(arProductCategory));
    }
}
